function getQueryString(url) {
    var pattern = /(\w+)=(\w+)/ig;//定义正则表达式 
	 var parames = {};//定义数组 
	 url.replace(pattern, function(a, b, c){ 
	  parames[b] = c; 
	 }); 
	 return parames; 
}
function JU_getCookie(objName){
	var arrStr = document.cookie.split("; ");
	for(var i = 0;i < arrStr.length;i ++){
	var temp = arrStr[i].split("=");
	if(temp[0] == objName) return unescape(temp[1]);   
	}
	return null;
}

function getViewportHeight() {
    if (window.innerHeight != window.undefined) {
        return window.innerHeight;
    }
    if (document.compatMode == "CSS1Compat") {
        return document.documentElement.clientHeight;
    }
    if (document.body) {
        return document.body.clientHeight;
    }
    return window.undefined;
}

var j_z_j_1="输入所有中国购物网站的商品链接地址就可以代购！";
var j_z_j_2="请您输入商品链接地址！";
var j_z_j_3="您输入的链接地址不正确，请核实后再填写！";
var j_z_j_4="恭喜您！商品信息抓取成功，您可以修改购买数量和填写商品备注！";
var j_z_j_5="请选填颜色、尺寸等要求！";
var j_z_j_6="请将您想代购商品的详细页网址粘贴到输入框中提交!";


if(JU_getCookie("dg_tpl")=='en'){
	
j_z_j_1="Please paste URL here!";
j_z_j_2="Please paste URL here!";
j_z_j_3="URL you entered is incorrect, please check before filling!";
j_z_j_4="Congratulations!  you can modify the number and fill out the goods purchased Remark!";
j_z_j_5="Please optional colors, sizes and other requirements!";
j_z_j_6="Please paste URL here!";
	
	
	
}


$(function() {
    $("#CrawlUrl").focus(function() {
        $("#CrawlPromt").removeClass("red").addClass("green").text(j_z_j_1);
        if ($("#CrawlUrl").val() == "http://") {
            $("#CrawlUrl").val("");
        }
    }).blur(function() {
        $("#CrawlPromt").removeClass("green");
        if ($.trim($("#CrawlUrl").val()).length <= 0) {
            $("#CrawlUrl").val("http://");
        }
    });
    var e = function() {
        var d = $.trim($("#CrawlUrl").val());
        if (d.length <= 0 || d == "http://") {
            $("#CrawlPromt").removeClass("green").addClass("red").text(j_z_j_2);
            return false;
        }
        var i = new RegExp("http(s)?://([\\w-]+\\.)+[\\w-]+(/[\\w- ./?%&=]*)?");
        if (d.indexOf("http://") < 0 && d.indexOf("https://") < 0) {
            d = "http://" + d;
        }
        if (!i.test(d)) {
            $("#CrawlPromt").removeClass("green").addClass("red").text(j_z_j_3);
            return false;
        }
       
		
		//alert(d.indexOf("taobao.com"))
		if (d.indexOf("taobao.com") >0  || d.indexOf("tmall.com") >0){
			//alert(d);
			var tt_id=getQueryString(d);
			
			if(typeof(tt_id['id']) == "undefined"){
				tt_id['id']=tt_id['mallstItemId'];
			}
			//alert(tid);
			//location.href="/get.php?gid="+tt_id['id'];
			location.href="/taobao.php?itemid="+tt_id['id'];
			return false;
		}
		
		$("#CrawlUrl").val("");
		FastAddShow(d);
        return false;
    };
    $("#CrawlUrl").keydown(function(d) {
        if (d.keyCode == 13) {
            e();
            return false;
        }
    });
    $("#CrawlBtn").click(e);
	
	
	var  f = function() {
        $("#CrawlUrl").val("");
		FastAddShow_NoURL("http://shipforme");
        return false;
    };
	
	$("#CrawlBtn1").click(f);
    var b = window.location.href;
    b = b.toLowerCase();
    if (b.indexOf("see") > 0) {
        $("#see").parent().addClass("current").next("b").remove();
    } else {
        if (b.indexOf("recommend") > 0) {
            $("#recommend").parent().addClass("current");
        } else {
            if (b.indexOf("shop") > 0) {
                $("#shop").parent().addClass("current").children("b").remove();
            } else {
                if (b.indexOf("t_b") > 0) {
                    $("#t_b").parent().addClass("current");
                } else {
					if (b.indexOf("guestbook") > 0) {
						$("#guestbook").parent().addClass("current");
					} else {
						if (b.indexOf("amazon") > 0) {
							$("#amazon").parent().addClass("current");
						} else {
							if (b.indexOf("zx") > 0) {
								$("#zx").parent().addClass("current");
							} else {
								if (b.indexOf("jp") > 0) {
									$("#jp").parent().addClass("current");
								}else{
									$("#Default").parent().addClass("current");
								}
							}
						}
					}
                }
            }
        }
    }
	

	
	
    $("#Tools,#ToolsList").hover(function() {
        $("#ToolsList").show();
    },
    function() {
        $("#ToolsList").hide();
    });
    //var a = new Date(parseInt($("#Beijing_Time").val())*1000);   
    //a.setMinutes(a.getMinutes());
    //setInterval(function() {
    //    a.setSeconds(a.getSeconds() + 1);
    //    $("#BeijingDate").html("北京时间：" + a.getFullYear() + "-" + (a.getMonth() < 9 ? "0": "") + (a.getMonth() + 1) + "-" + (a.getDate() < 9 ? "0": "") + a.getDate());
    //    $("#BeijingTime").html("<span>" + (a.getHours()) + "</span><b></b><span>" + (a.getMinutes() < 10 ? "0": "") + a.getMinutes() + "</span><b></b><span>" + (a.getSeconds() < 10 ? "0": "") + a.getSeconds() + "</span>");
    //},
   // 1000);

	if (typeof document.body.style.maxHeight == "undefined") {
		//if ($.browser.msie && $.browser.version == "6.0") {
		$(".addpanel_dialog").css("position", "absolute").css("margin-top", "0px");
		var divY = (getViewportHeight() - $(".addpanel_dialog").outerHeight()) / 2;
		$(".addpanel_dialog").css("top", (divY + document.documentElement.scrollTop).toString());
		$(window).scroll(function() { $(".addpanel_dialog").css("top", divY + document.documentElement.scrollTop + ""); });
	}	
	
});

function getViewportHeight() { if (window.innerHeight != window.undefined) { return window.innerHeight } if (document.compatMode == "CSS1Compat") { return document.documentElement.clientHeight } if (document.body) { return document.body.clientHeight } return window.undefined }
function InitP2() {
    $("#proAlert").attr("class", "").text(j_z_j_4);
    $("#productUrl").val("");
    $("#productName").val("").attr("class", "addpanel_k").removeAttr("disabled").unbind("focus").unbind("blur");
    $("#productPrice").val("").attr("class", "").removeAttr("disabled").unbind("focus").unbind("blur");
    $("#productSendPrice").val("").attr("class", "").unbind("focus");
    $("#productNum").val("1");
    $("#productImg").hide();
    $("#isAuction").hide();
    $("#productImg img").attr("src", "");
    $("#productRemark").attr("class", "addpanel_still").text(j_z_j_5);
    $("#successBtn").attr("disabled", "disabled").attr("class", "addpanel_next_no");
    $("#vipPriceS").remove();
}
function InitP4_SFM() {
    $("#proAlert").attr("class", "").text(j_z_j_4);
    $("#productUrl").val("");
    $("#productUrl").removeAttr("disabled");
    $("#productName").val("").attr("class", "addpanel_k").removeAttr("disabled").unbind("focus").unbind("blur");
    $("#productPrice").val("").attr("class", "").removeAttr("disabled").unbind("focus").unbind("blur");
    $("#productSendPrice").val("").attr("class", "").unbind("focus");
    $("#productNum").val("1");
    $("#productImg").hide();
    $("#isAuction").hide();
    $("#productImg img").attr("src", "");
    $("#productRemark").attr("class", "addpanel_still").text(j_z_j_5);
    $("#successBtn").attr("disabled", "disabled").attr("class", "addpanel_next_no");
	$("#expressno").val("");
    $("#vipPriceS").remove();
}
function p3Init() {
    $("#p3_img").attr("src", "/add/newimages/noimg80.gif");
}

function p5Init() {
    $("#p5_img").attr("src", "/add/newimages/noimg80.gif");
}


//执行抓取操作
function FastAdd_Submit(){
	$("#addpanel_submit").click(); 
}
function FastAddShow(url) {
	$(".addpanel_overlay").height($(document).height()).show();
    $(".addpanel_dialog").show();
    if ($("#p1 div").length == 0)
        $("#p1").load("/add/AddItemPanel/AddItemPanel1.htm", function() { 
		$("#p0").remove(); 
		$("#p1").show(); 
		if(JU_getCookie("dg_tpl")=='en'){
			$('#j_guide_img').attr('src','/add/newimages/procedure_en.gif');
		}
			if(url==null){
				$("#itemUrl").focus();
			}else{
				$("#itemUrl").val(url).focus();
				setTimeout("FastAdd_Submit()",500);
				return false;
			}
		});
    else {
		if(url==null){
			$("#itemUrl").focus();
		}else{
			$("#itemUrl").val(url).focus();
			setTimeout("FastAdd_Submit()",500);
			return false;
		}
	}
	
    if ($("#p2 div").length == 0){
       $("#p2").load("/add/AddItemPanel/AddItemPanel2.htm", function() { 
		   $("#p2").hide(); 	
		   if(JU_getCookie("dg_tpl")=='en'){
				$('#j_guide_img').attr('src','/add/newimages/procedure_en.gif');
				$('#j_add_pan_2_1').text('Goods URL:');
				$('#proAlert').text('Congratulations! You can modify the purchase amount and fill Remarks!');
				$('#j_add_pan_2_2').text('Product Name:');
				$('#j_add_pan_2_3').text('Price:');
				$('#j_add_pan_2_4').text('Domestic Shipping:');
				$('#j_add_pan_2_5').text('Quantity:');
				$('#j_add_pan_2_6').text('Size:');
				$('#j_add_pan_2_7').text('Color:');
				$('#j_add_pan_2_8').text('Note:');
				$('#productRemark').val('Please optional colors, sizes and other requirements!');
				$('#btnCls').text('[Clear]');
				$('#j_dfdf').html('Ship');
				$('#type1').text('Please ship for me');
				$('#type2').html('&nbsp;Express No:<input name="expressno" type="input" id="expressno" style="width:80px;" value="">&nbsp;<font color="#ff9900">*Fill</font>');
				if($("#j_guide_img").length > 0){
					$('#j_guide_img').attr('src','/add/newimages/procedure_en.gif');
				}
				if($("#successBtn").length > 0){
					$('#successBtn').css('background-image','url(/add/newimages/go_en.gif)');
				}
		   }//en
		});
	}
    if ($("#p3 div").length == 0)
       $("#p3").load("/add/AddItemPanel/AddItemPanel3.htm", function() { $("#p3").hide(); });
}


function FastAddShow_NoURL(url) {
	$(".addpanel_overlay").height($(document).height()).show();
    $(".addpanel_dialog").show();
$("#p4").load("/add/AddItemPanel/AddItemPanel2_SFM.htm", function() { $("#p0").remove(); $("#p1").hide(); $("#p4").show();  });		
    $("#p5").load("/add/AddItemPanel/AddItemPanel3_SFM.htm", function() { $("#p5").hide(); });
}









function AddItemClose() {
    $(".addpanel_dialog").hide();
    $(".addpanel_overlay").hide();
    if ($("#p2 div").length >= 1) {
        $("#p2").hide();
        InitP2();
    }
    if ($("#p3 div").length >= 1) {
        $("#p3").hide();
        p3Init();
    }
    $(".addpanel_address_").attr("class", "addpanel_address");
    $("#itemUrl").removeAttr("disabled").val("");

    $("#promptInfo").attr("class", "addpanel_dhk").find("img").remove();
    $("#promptInfo p").text(j_z_j_6);
    $("#addpanel_submit").removeAttr("disabled").attr("class", "addpanel_tijiao");
    $("#p1").show();
}

$("#closeBtn").click(AddItemClose);
var browser = navigator.appName;
var b_version = navigator.appVersion;
var version = parseFloat(b_version);
navigator.compitable

